from lxml import etree

html ='''
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <meta itemprop="haha" name='keywords' itemscope='test'>
    <link rel="stylesheet" href="http://1.com" title="1">
    <style>
        #demo{
            width: 100;
            height: 100;
            background-color: cornflowerblue;
        }
    </style>
    <script>
        var a=1;
        console.log(a);
    </script>
</head>
<body>
    <div id="demo">这是一个测试</div>
    <a href="http://www.baidu.com" title="hello world">
        <img src="/demo.jpeg" alt="img">
    </a>
    <a href="http://www.bilibili.com" title=""></a>
    <a href="http://haha.com" title>
        <p>联系我们</p>
    </a>
    <font>8 (499) 517-88-99</font>
    <font>8 (800) 200-10-70</font>
</body>
</html>
'''
emt = etree.HTML(html)
# href_emt = emt.xpath('//body//*[@href and @title!=""]/@href')
# res = emt.xpath(r'//font[re:match(text(),"[ \d()+-.]{2,}")]/text()',namespaces={"re": "http://exslt.org/regular-expressions"})
res = emt.xpath(r'//*[contains(text(),"联系我们")]/@href')
res1 = emt.xpath(r'//a/text()')
# r'//*[re:match(@id, "postmessage_\d+")]'
print(res1)